<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$semester_id = mysql_real_escape_string(strip_tags($_GET['id']));

//counting variable
$i = 0;

$get_semester_data=mysql_query("SELECT * 
								FROM seasons 
								JOIN semesters
								ON semesters.season_id=seasons.id
								WHERE semesters.id='$semester_id'");
								
$orig_session_number=mysql_result($get_semester_data,$i,"semesters.session_number");
$orig_year=mysql_result($get_semester_data,$i,"semesters.year");		
$orig_season_id=mysql_result($get_semester_data,$i,"seasons.id");
		
$orig_start_date=mysql_result($get_semester_data,$i,"semesters.start_date");
$orig_end_date=mysql_result($get_semester_data,$i,"semesters.end_date");

echo "<h1>Add Semester</h1>";

echo "<p>";
	echo "<b>Please enter date in YYYY-MM-DD format</b>";
echo "</p>";
	
echo '<p>';

echo "<form action='edit_do.php' method='post'>";

//start table
echo "<table border='0'>";
	
	//create table row
	echo "<tr>";
		echo "<td width=180><b>Session Number: </b></td>";
		echo "<td><input type='text' name='session_num' value='$orig_session_number'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Year: </b></td>";
		echo "<td><input type='text' name='year' value='$orig_year'></td>";
	echo "</tr>";
	
	$result=mysql_query("SELECT * FROM seasons ORDER BY season");
	$num_rows=mysql_numrows($result);
	
	echo "<tr>";
		echo "<td><b>Season:</b></td>";
		echo "<td>";
			echo "<select name='season'>";
				while ($i < $num_rows)
				{
					$season_id=mysql_result($result,$i,"id");
					$season=mysql_result($result,$i,"season");
					if ($season_id == $orig_season_id)
					{
						echo "<option value=$season_id selected='selected'>$season</option>";
					}
					else
					{
						echo "<option value=$season_id>$season</option>";
					}
					
					$i++;
				}
			echo "</select>";
		echo '</td>';
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Start Date: </b></td>";
		echo "<td><input type='text' name='start' value='$orig_start_date'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>End Date: </b></td>";
		echo "<td><input type='text' name='end' value='$orig_end_date'></td>";
	echo "</tr>";
	
//end table tag
echo "</table>";

//close
mysql_close();

echo "<input type='hidden' name='id' value='$semester_id'>";
echo '<input type="submit">';
echo '</form>';

echo "<p>";
	echo "<a href='index.php'>&lt;&lt; Back to Semesters Portal</a><br />";
echo "</p>";

?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>